package jjwc.fsy;

import jakarta.inject.Inject;
import jakarta.inject.Provider;
import org.opentcs.access.Kernel;
import org.opentcs.access.SharedKernelServicePortalProvider;
import org.opentcs.components.plantoverview.PluggablePanel;
import org.opentcs.components.plantoverview.PluggablePanelFactory;

import java.util.ResourceBundle;

import static java.util.Objects.requireNonNull;

public class MsgShowPanelFactory implements PluggablePanelFactory {

  /**
   * This classe's bundle.
   */
  private final ResourceBundle bundle = ResourceBundle.getBundle("Bundle");
  /**
   * The provider for the portal.
   */
  private final SharedKernelServicePortalProvider portalProvider;

  /**
   * The provider for the panel this factory wants to create.
   */
  private final Provider<MsgShowPanel> panelProvider;



  @Inject
  public MsgShowPanelFactory(SharedKernelServicePortalProvider portalProvider,
                                        Provider<MsgShowPanel> panelProvider) {
    this.portalProvider = requireNonNull(portalProvider, "portalProvider");
    this.panelProvider = requireNonNull(panelProvider, "panelProvider");
  }


  @Override
  public boolean providesPanel(Kernel.State state) {
    return (state == Kernel.State.OPERATING);
  }

  @Override
  public String getPanelDescription() {
    return bundle.getString("msgShowpanel.panelDescription");
  }

  @Override
  public PluggablePanel createPanel(Kernel.State state) {
    if (state != Kernel.State.OPERATING) {
      return null;
    }
    if (portalProvider == null || !portalProvider.portalShared()) {
      return null;
    }
    return panelProvider.get();
  }
}
